#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>


void tournament(int n, int** schedule) {
    if (n == 1) return;
    int m = n / 2;


    tournament(m, schedule);
    int i, j = 0;

    for (i = 0; i < m; i++) {
        for (j = 0; j < m; j++) {
            schedule[i + m][j] = schedule[i][j + m];
            schedule[i][j + m] = schedule[i + m][j];
        }
    }
}

int main() {
    int n = 4;
    int** schedule = (int**)malloc(n * sizeof(int*));
    int i, j = 0;
    for (i = 0; i < n; i++) {
        schedule[i] = (int*)malloc(n * sizeof(int));
        schedule[i][i] = i + 1;
    }


    tournament(n, schedule);


    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            printf("%d\t", schedule[i][j]);
        }
        printf("\n");
    }


    for (i = 0; i < n; i++) {
        free(schedule[i]);
    }
    free(schedule);

    return 0;
}






















